Skip to content

perf: defer matplotlib imports and lazy-load plot submodule#427

Merged
Jammy2211 merged 1 commit intomainfrom
feature/lazy-imports
Apr 7, 2026
Merged

perf: defer matplotlib imports and lazy-load plot submodule#427
Jammy2211 merged 1 commit intomainfrom
feature/lazy-imports

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Replace module-level import matplotlib.pyplot as plt with subplots() wrappers from autoarray.plot.utils across all plot files. Update plot_utils imports to use the new autogalaxy.util.plot_utils path. Lazy-load the plot submodule via __getattr__ in autolens/__init__.

Combined with scipy deferral (PyAutoArray#259, PyAutoFit#1186) and matplotlib deferral (PyAutoGalaxy#330), total import autolens time drops from ~2.7s to ~1.9s (30% reduction).

Part of #426. Depends on PyAutoLabs/PyAutoArray#259, PyAutoLabs/PyAutoGalaxy#330.

API Changes

None — internal changes only.

Test Plan

  • pytest test_autolens/ -x — 245 passed
  • Smoke tests via downstream /smoke-test
Full API Changes (for automation & release notes)

Internal

  • All import matplotlib.pyplot as plt removed from plot files, replaced with subplots from autoarray.plot.utils
  • All from autogalaxy.plot.plot_utils imports updated to from autogalaxy.util.plot_utils
  • autolens.plot submodule lazy-loaded via __getattr__ in autolens/__init__

🤖 Generated with Claude Code

Replace module-level matplotlib imports with autoarray.plot.utils
wrappers across all plot files. Update plot_utils imports to use the
new autogalaxy.util.plot_utils path. Lazy-load the plot submodule via
__getattr__ in autolens/__init__, deferring matplotlib import cost to
first plot access.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit 6f20d6c into main Apr 7, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant